using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace App
{
    public class PanDown : System.Windows.Forms.Panel
    {
        private bool m_IsTop = true;

        public bool IsTop
        {
            get { return m_IsTop; }
            set
            {
                m_IsTop = value;
                Invalidate();
            }
        }

        public PanDown()
        {
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        }


        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
            e.Graphics.CompositingQuality = CompositingQuality.HighQuality;

            if (ClientRectangle.Width == 0 || ClientRectangle.Height == 0)
                return;
            e.Graphics.Clear(Common.Blue);
            Rectangle rect = new Rectangle(0, 0, this.Width - 1, this.Height - 1);

            Color[] col = new Color[] { Color.FromArgb(225, 234, 245), Color.FromArgb(209, 223, 240), 
                            Color.FromArgb(199, 216, 237), Color.FromArgb(231, 242, 255) };
            float[] pos = new float[] { 0.0f, 0.4f, 0.4f, 1.0f };

            LinearGradientBrush brush = DrawHelper.GetBrush(col, pos, rect);
            DrawHelper.FillRoundRectangle(e.Graphics, brush, rect, 1f);
            DrawHelper.DrawRoundRectangle(e.Graphics, new Pen(Color.FromArgb(141, 178, 227)), rect, 1f);
            rect.Offset(1, 1);
            rect.Width -= 2;
            rect.Height -= 2;
            using (LinearGradientBrush b = new LinearGradientBrush(rect,
                Color.FromArgb(231, 239, 248), Color.Transparent, LinearGradientMode.ForwardDiagonal))
            {
                DrawHelper.DrawRoundRectangle(e.Graphics, new Pen(b), rect, 1f);
            }
            brush.Dispose();
        }

        protected override void OnResize(EventArgs eventargs)
        {
            base.OnResize(eventargs);
            this.Invalidate();
        }
    }
}
